/**
 * CustomNumAdapter.java [V 1.0.0]
 * classes : com.xiaocq.wordsgod.CustomNumAdapter
 * xiaocq Create at 2012-7-17 上午10:48:28
 */
package com.xiaocq.wordsgod;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * com.xiaocq.wordsgod.CustomNumAdapter
 * @author Mystory
 * Create at 2012-7-17 上午10:48:28
 */
public class NumAdapter extends BaseAdapter{
	private int[] list;
	private LayoutInflater inflater;
	
	public NumAdapter(Context context, int[] list){
		this.list = list;
		inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	public int getCount() {
		return list.length;
	}

	public Object getItem(int position) {
		return list[position];
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if(convertView == null){
			convertView = inflater.inflate(R.layout.wrongset_index_item, null);
			holder = new ViewHolder();
			holder.index = (TextView) convertView.findViewById(R.id.wrongset_unit);
			holder.num = (TextView) convertView.findViewById(R.id.wrongset_num);
			convertView.setTag(holder);
		}else{
			holder = (ViewHolder) convertView.getTag();
		}
		int number = list[position];
		holder.index.setText("Unit " + (position + 1));
		if(number != 0){
			holder.num.setText(Integer.toString(number) + "个");
		}else{
			holder.num.setText("-");
		}
		return convertView;
	}

	static class ViewHolder{
		TextView index;
		TextView num;
	}
}
